function Reducer(state,action){
	switch (action.type){
		case 'GET_PRODUCT_DATA_START':
			return Object.assign({},state,{
				status:'正在获取'
			})
		case 'GET_PRODUCT_DATA_END':
			return Object.assign({},state,{
				list:action.todolist,
				status:'获取成功'
			})
		case 'ADD_TO_CAR':
			var newList=[];
			newList=[...state.carlist];
			var obj={};
			console.log(state);
			//console.log(action.id);
			for(var i=0;i<state.list.length;i++){				
				if(state.list[i].id==action.id){
					if(state.carlist.length==0){
						var obj=state.list[i];
						obj.inventory=1;
						newList.push(obj);
					}else{
						var arr=[];
						for(var j=0;j<newList.length;j++){
							arr.push(newList[j].id);
						}
						console.log(arr);
						if(arr.indexOf(action.id)==-1){
							console.log(obj);
							var obj=state.list[i];
							obj.inventory=1;
							newList.push(obj);
						}else{
							newList[arr.indexOf(action.id)].inventory++;
						}		
					}					
								
				}
			}
			return Object.assign({},state,{
				carlist:newList
			})
		case 'RM_FROM_CAR':
			var newList=[];
			newList=[...state.carlist];
			for(var i=0;i<newList.length;i++){				
				if(newList[i].id==action.id){
					console.log(state.list[i].id);
					console.log(action.id);
					console.log(i);
					newList.splice(i,1);
					break;
				}
			}
			return Object.assign({},state,{
				carlist:newList
			})
		default:
			return state;
	}
}

export default Reducer;